<?php
namespace App\Repositories\BLL\Wechat;
use Illuminate\Support\Facades\DB;

class MessageBLL
{
			
	public function receiveText($message){
		$res="";
		$openid = $message->FromUserName;
		//获取openid对应的微信墙id，并查看是否过期
		$wall = DB::table('wechat_users')
					->join('walls', 'wechat_users.wallid', '=', 'walls.id')
					->select('wechat_users.wallid')
					->where([['wechat_users.openid','=',$openid],['walls.failure_date','>=',date('Y-m-d')]])
					->first();
		if($wall){
			if($message->Content == "【收到不支持的消息类型，暂无法显示】"){
				$res="您发送的消息暂不支持！";
			}else{
				//写入微信墙
				DB::table('wall_chats')->insert(
				    ['wallid' => $wall->wallid
				    , 'openid' => $openid
				    , 'value'=>$message->Content
				    , 'send_time'=>date('Y-m-d H:i:s')]
				);
				$res="上墙成功，请看大屏！";
			}
		}else{
			//非微信墙活动，停止后续消息发送
			DB::table('msg_logs')
				->where([['status', '=', '0'],['openid','=',$openid]])
				->update(['status' => 2]);

			//转发消息给客服
			$res = "CustomerService";
		}
		
		return $res;
	}
}